/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.dao.ActiSingUpDao;
import com.qdu.dao.UsersDao;
import com.qdu.entity.ActiSingUp;
import com.qdu.entity.Log;
import com.qdu.entity.Users;
import com.qdu.service.impl.LogServiceImpl;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 发表日志按钮点击之后
 *
 * @author Lenovo
 */
@WebServlet("/pols")
public class publishOneLogServlet extends HttpServlet{
   UsersDao userdao=new UsersDao();
    LogServiceImpl logserviceimpl=new LogServiceImpl();
    ActiSingUpDao actisignup=new ActiSingUpDao();
    Log log=new Log();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        String actId=req.getParameter("actId");//活动编号
        HttpSession session=req.getSession(false);
        String content=req.getParameter("text");
        String imag=req.getParameter("image");
        String name=req.getParameter("title");
        String uid=(String)session.getAttribute("PageUid");
            if(null==uid)
            {
                resp.sendRedirect("Userlogin.html");
            }
            else{
                List<ActiSingUp> act=actisignup.getActivByAid(uid);
                System.out.println(uid);
                for(ActiSingUp a:act)
                {
                    if(a.getActivityId().equals(actId))//如果该用户参加了这个活动
                    {
                        log.setActivityId(actId);
                        log.setAgree(0);
                        log.setContent(content);
                        log.setImag(imag);
                        log.setName(name);
                        log.setUserid(uid);
                        int rows=logserviceimpl.addNewLog(log);
                        System.out.println(rows);
                        resp.sendRedirect("salfm");//跳转到日志表页面
                        return;
                    }
                }
                resp.setContentType("text/html;charset=utf-8");
                PrintWriter out=resp.getWriter();
                out.println("<h1>您未参加此次活动，不能发表日志</h1>");
            }
        }
    }

